home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / Hardware / FreeWheel / GUI.c < prev    next >
C/C++ Source or Header  |  2000-03-12  |  14KB  |  463 lines

  1.  
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <exec/types.h>
  6. #include <libraries/gadtools.h>
  7. #include <intuition/GadgetClass.h>
  8. #include <intuition/Screens.h>
  9.  
  10. #include <clib/gadtools_protos.h>
  11. #include <clib/intuition_protos.h>
  12.  
  13. #include "GUI.h"
  14.  
  15. struct TextAttr GUI_DefaultFont = { "topaz.font", 8, 0, 0};
  16.  
  17. void GUI_Dispose(struct GUIContext *gui);
  18.  
  19.  
  20. void GUI_Attach(struct GUIContext *gui,struct Window *win)
  21. {
  22.   AddGList(win,gui->ContextGadget,0,-1,NULL);
  23.   RefreshGList(gui->ContextGadget,win,NULL,-1);
  24.   GT_RefreshWindow(win, NULL);
  25. }
  26.  
  27.  
  28. struct Gadget *GUI_BuildButton(struct GUIContext *gui,char *text,long id)
  29. {
  30.   struct NewGadget newgad;
  31.   int topedge,leftedge,textwidth,gadgetheight;
  32.  
  33.   if(gui->LastGadget)
  34.   {
  35.     textwidth=32+TextLength(&gui->Screen->RastPort,text,strlen(text));
  36.  
  37.     topedge=gui->BorderTop+gui->InnerHeight;
  38.     leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
  39.     gadgetheight=gui->TextAttr->ta_YSize+6;
  40.     gui->InnerHeight+=8+gadgetheight;
  41.  
  42.     newgad.ng_TextAttr   = gui->TextAttr;
  43.     newgad.ng_VisualInfo = gui->VisualInfo;
  44.     newgad.ng_LeftEdge   = leftedge;
  45.     newgad.ng_TopEdge    = topedge;
  46.     newgad.ng_Width      = textwidth;
  47.     newgad.ng_Height     = gadgetheight;
  48.     newgad.ng_GadgetText = text;
  49.     newgad.ng_GadgetID   = id;
  50.     newgad.ng_Flags      = 0;
  51.  
  52.     gui->LastGadget = CreateGadget(BUTTON_KIND, gui->LastGadget, &newgad,
  53.                              GA_RelVerify,TRUE,
  54.                              TAG_DONE);
  55.     gui->IDCMP|=BUTTONIDCMP;
  56.   }
  57.   return(gui->LastGadget);
  58. }
  59.  
  60.  
  61. struct Gadget *GUI_BuildWideButton(struct GUIContext *gui,char *text,long id)
  62. {
  63.   struct NewGadget newgad;
  64.   int topedge,leftedge,textwidth,gadgetheight;
  65.  
  66.   if(gui->LastGadget)
  67.   {
  68.     textwidth=16+TextLength(&gui->Screen->RastPort,text,strlen(text));
  69.     if(textwidth<(gui->InnerWidth-16))
  70.       textwidth=gui->InnerWidth-16;
  71.     else
  72.       gui->InnerWidth=textwidth+16;
  73.     topedge=gui->BorderTop+gui->InnerHeight;
  74.     leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
  75.     gadgetheight=gui->TextAttr->ta_YSize+6;
  76.     gui->InnerHeight+=8+gadgetheight;
  77.  
  78.     newgad.ng_TextAttr   = gui->TextAttr;
  79.     newgad.ng_VisualInfo = gui->VisualInfo;
  80.     newgad.ng_LeftEdge   = leftedge;
  81.     newgad.ng_TopEdge    = topedge;
  82.     newgad.ng_Width      = textwidth;
  83.     newgad.ng_Height     = gadgetheight;
  84.     newgad.ng_GadgetText = text;
  85.     newgad.ng_GadgetID   = id;
  86.     newgad.ng_Flags      = 0;
  87.  
  88.     gui->LastGadget = CreateGadget(BUTTON_KIND, gui->LastGadget, &newgad,
  89.                              GA_RelVerify,TRUE,
  90.                              TAG_DONE);
  91.     gui->IDCMP|=BUTTONIDCMP;
  92.   }
  93.   return(gui->LastGadget);
  94. }
  95.  
  96.  
  97. struct Gadget *GUI_BuildText(struct GUIContext *gui,char *text)
  98. {
  99.   struct NewGadget newgad;
  100.   int topedge,leftedge,textwidth,textwidth2,gadgetheight;
  101.  
  102.   if(gui->LastGadget)
  103.   {
  104.     textwidth=32+TextLength(&gui->Screen->RastPort,text,strlen(text));
  105.     if(textwidth<(gui->InnerWidth-16))
  106.       textwidth=gui->InnerWidth-16;
  107.     else
  108.       gui->InnerWidth=textwidth+16;
  109.  
  110.     topedge=gui->BorderTop+gui->InnerHeight;
  111.     leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
  112.     gadgetheight=gui->TextAttr->ta_YSize+6;
  113.     gui->InnerHeight+=gadgetheight+4;
  114.  
  115.     newgad.ng_TextAttr   = gui->TextAttr;
  116.     newgad.ng_VisualInfo = gui->VisualInfo;
  117.     newgad.ng_LeftEdge   = leftedge;
  118.     newgad.ng_TopEdge    = topedge;
  119.     newgad.ng_Width      = textwidth;
  120.     newgad.ng_Height     = gadgetheight;
  121.     newgad.ng_GadgetText = 0;
  122.     newgad.ng_GadgetID   = 0;
  123.     newgad.ng_Flags      = 0;
  124.  
  125.     gui->LastGadget = CreateGadget(TEXT_KIND, gui->LastGadget, &newgad,
  126.                              GTTX_Border,FALSE,
  127.                              GTTX_Text,text,
  128.                              GTTX_Justification,GTJ_CENTER,
  129.                              GTTX_Clipped,TRUE,
  130.                              TAG_DONE);
  131.     gui->IDCMP|=TEXTIDCMP;
  132.   }
  133.   return(gui->LastGadget);
  134. }
  135.  
  136.  
  137. struct Gadget *GUI_BuildCheckBox(struct GUIContext *gui,char *text,long id)
  138. {
  139.   struct NewGadget newgad;
  140.   int topedge,leftedge,textwidth,guiwidth,gadgetwidth,gadgetheight;
  141.  
  142.   textwidth=0;
  143.   if(gui->LastGadget)
  144.   {
  145.     gadgetwidth=gadgetheight=gui->TextAttr->ta_YSize+8;
  146.     if(text)
  147.       textwidth=8+TextLength(&gui->Screen->RastPort,text,strlen(text));
  148.     if(gui->TabStop>textwidth)
  149.       textwidth=gui->TabStop;
  150.     if(textwidth>(gui->InnerWidth-16))
  151.       gui->InnerWidth=textwidth+gadgetwidth+16;
  152.     guiwidth=gui->InnerWidth-16;
  153.  
  154.     topedge=gui->BorderTop+gui->InnerHeight;
  155.     leftedge=8+gui->BorderLeft+textwidth;
  156.     gui->InnerHeight+=6+gadgetheight;
  157.  
  158.     newgad.ng_TextAttr   = gui->TextAttr;
  159.     newgad.ng_VisualInfo = gui->VisualInfo;
  160.     newgad.ng_LeftEdge   = leftedge;
  161.     newgad.ng_TopEdge    = topedge;
  162.     newgad.ng_Width      = gadgetwidth;
  163.     newgad.ng_Height     = gadgetheight;
  164.     newgad.ng_GadgetText = text;
  165.     newgad.ng_GadgetID   = id;
  166.     newgad.ng_Flags      = PLACETEXT_LEFT;
  167.  
  168.     gui->LastGadget = CreateGadget(CHECKBOX_KIND, gui->LastGadget, &newgad,
  169.                              GA_RelVerify,TRUE,
  170.                              GTCB_Scaled,TRUE,
  171.                              TAG_DONE);
  172.     gui->IDCMP|=CHECKBOXIDCMP;
  173.   }
  174.   return(gui->LastGadget);
  175. }
  176.  
  177.  
  178. struct Gadget *GUI_BuildSlider(struct GUIContext *gui,char *text,int min,int max,int level,long id)
  179. {
  180.   struct NewGadget newgad;
  181.   int topedge,leftedge,textwidth,guiwidth,gadgetwidth,gadgetheight;
  182.  
  183.   textwidth=0;
  184.   if(gui->LastGadget)
  185.   {
  186.     if(text)
  187.       textwidth=8+TextLength(&gui->Screen->RastPort,text,strlen(text));
  188.     if(gui->TabStop>textwidth)
  189.       textwidth=gui->TabStop;
  190.     if(textwidth>(gui->InnerWidth-16))
  191.       gui->InnerWidth=textwidth+100;
  192.     guiwidth=gui->InnerWidth-16;
  193.  
  194.     gadgetwidth=guiwidth-textwidth;
  195.     topedge=gui->BorderTop+gui->InnerHeight;
  196.     leftedge=8+gui->BorderLeft+textwidth;
  197.     gadgetheight=gui->TextAttr->ta_YSize+8;
  198.     gui->InnerHeight+=6+gadgetheight;
  199.  
  200.     newgad.ng_TextAttr   = gui->TextAttr;
  201.     newgad.ng_VisualInfo = gui->VisualInfo;
  202.     newgad.ng_LeftEdge   = leftedge;
  203.     newgad.ng_TopEdge    = topedge;
  204.     newgad.ng_Width      = gadgetwidth;
  205.     newgad.ng_Height     = gadgetheight;
  206.     newgad.ng_GadgetText = text;
  207.     newgad.ng_GadgetID   = id;
  208.     newgad.ng_Flags      = PLACETEXT_LEFT;
  209.  
  210.     gui->LastGadget = CreateGadget(SLIDER_KIND, gui->LastGadget, &newgad,
  211.                              GA_RelVerify,TRUE,
  212.                              GTSL_Min,min,
  213.                              GTSL_Max,max,
  214.                              GTSL_Level,level,
  215.                              TAG_DONE);
  216.     gui->IDCMP|=SLIDERIDCMP;
  217.   }
  218.   return(gui->LastGadget);
  219. }
  220.  
  221.  
  222. struct Gadget *GUI_BuildSliderFormatted(struct GUIContext *gui,char *text,int min,int max,int level,long id)
  223. {
  224.   struct NewGadget newgad;
  225.   int topedge,leftedge,textwidth,guiwidth,gadgetwidth,gadgetheight;
  226.  
  227.   textwidth=0;
  228.   if(gui->LastGadget)
  229.   {
  230.     if(text)
  231.       textwidth=8+TextLength(&gui->Screen->RastPort,text,strlen(text));
  232.     if(gui->TabStop>textwidth)
  233.       textwidth=gui->TabStop;
  234.     if(textwidth>(gui->InnerWidth-16))
  235.       gui->InnerWidth=textwidth+100;
  236.     guiwidth=gui->InnerWidth-16;
  237.  
  238.     gadgetwidth=guiwidth-textwidth;
  239.     topedge=gui->BorderTop+gui->InnerHeight;
  240.     leftedge=8+gui->BorderLeft+textwidth;
  241.     gadgetheight=gui->TextAttr->ta_YSize+8;
  242.     gui->InnerHeight+=6+gadgetheight;
  243.  
  244.     newgad.ng_TextAttr   = gui->TextAttr;
  245.     newgad.ng_VisualInfo = gui->VisualInfo;
  246.     newgad.ng_LeftEdge   = leftedge;
  247.     newgad.ng_TopEdge    = topedge;
  248.     newgad.ng_Width      = gadgetwidth;
  249.     newgad.ng_Height     = gadgetheight;
  250.     newgad.ng_GadgetText = NULL;
  251.     newgad.ng_GadgetID   = id;
  252.     newgad.ng_Flags      = PLACETEXT_LEFT;
  253.  
  254.     gui->LastGadget = CreateGadget(SLIDER_KIND, gui->LastGadget, &newgad,
  255.                              GA_RelVerify,TRUE,
  256.                              GTSL_Min,min,
  257.                              GTSL_Max,max,
  258.                              GTSL_Level,level,
  259.                              GTSL_LevelFormat,text,
  260.                              GTSL_MaxLevelLen,strlen(text)+4,
  261.                              TAG_DONE);
  262.     gui->IDCMP|=SLIDERIDCMP;
  263.   }
  264.   return(gui->LastGadget);
  265. }
  266.  
  267.  
  268. struct Gadget *GUI_BuildCycleGadget(str